{"ast":null,"code":"import _classCallCheck from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/classCallCheck.js\";\nimport _createClass from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/createClass.js\";\nimport { Md5 } from './md5';\n// Hashes any blob\nexport var Md5FileHasher = /*#__PURE__*/function () {\n  function Md5FileHasher(_callback) {\n    var _async = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n    var _partSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1048576;\n    _classCallCheck(this, Md5FileHasher);\n    this._callback = _callback;\n    this._async = _async;\n    this._partSize = _partSize;\n    this._configureReader();\n  }\n  /**\n   * Hash a blob of data in the worker\n   * @param blob Data to hash\n   */\n  _createClass(Md5FileHasher, [{\n    key: \"hash\",\n    value: function hash(blob) {\n      var self = this;\n      self._blob = blob;\n      // self._length = Math.ceil(blob.size / self._partSize);\n      self._part = 0;\n      self._md5 = new Md5();\n      self._processPart();\n    }\n  }, {\n    key: \"_fail\",\n    value: function _fail() {\n      this._callback({\n        success: false,\n        result: 'data read failed'\n      });\n    }\n  }, {\n    key: \"_hashData\",\n    value: function _hashData(e) {\n      var self = this;\n      self._md5.appendByteArray(new Uint8Array(e.target.result));\n      if (self._part * self._partSize >= self._blob.size) {\n        self._callback({\n          success: true,\n          result: self._md5.end()\n        });\n      } else {\n        self._processPart();\n      }\n    }\n  }, {\n    key: \"_processPart\",\n    value: function _processPart() {\n      var self = this;\n      var endbyte = 0;\n      var current_part;\n      self._part += 1;\n      if (self._blob.size > self._partSize) {\n        // If blob bigger then part_size we will slice it up\n        endbyte = self._part * self._partSize;\n        if (endbyte > self._blob.size) {\n          endbyte = self._blob.size;\n        }\n        current_part = self._blob.slice((self._part - 1) * self._partSize, endbyte);\n      } else {\n        current_part = self._blob;\n      }\n      if (self._async) {\n        self._reader.readAsArrayBuffer(current_part);\n      } else {\n        setTimeout(function () {\n          try {\n            self._hashData({\n              target: {\n                result: self._reader.readAsArrayBuffer(current_part)\n              }\n            });\n          } catch (e) {\n            self._fail();\n          }\n        }, 0);\n      }\n    }\n  }, {\n    key: \"_configureReader\",\n    value: function _configureReader() {\n      var self = this;\n      if (self._async) {\n        self._reader = new FileReader();\n        self._reader.onload = self._hashData.bind(self);\n        self._reader.onerror = self._fail.bind(self);\n        self._reader.onabort = self._fail.bind(self);\n      } else {\n        self._reader = new FileReaderSync();\n      }\n    }\n  }]);\n  return Md5FileHasher;\n}();","map":{"version":3,"mappings":";;AAAA,SAAQA,GAAG,QAAO,OAAO;AASzB;AACA,WAAaC,aAAa;EAStB,uBACYC,SAAuC,EAEZ;IAAA,IAD3BC,6EAAkB,IAAI;IAAA,IACtBC,gFAAoB,OAAO;IAAA;IAF3B,cAAS,GAATF,SAAS;IACT,WAAM,GAANC,MAAM;IACN,cAAS,GAATC,SAAS;IAEjB,IAAI,CAACC,gBAAgB,EAAE;EAC3B;EAEA;;;;EAAA;IAAA;IAAA,OAIO,cAAKC,IAAS;MACjB,IAAMC,IAAI,GAAG,IAAI;MAEjBA,IAAI,CAACC,KAAK,GAAGF,IAAI;MACjB;MACAC,IAAI,CAACE,KAAK,GAAG,CAAC;MACdF,IAAI,CAACG,IAAI,GAAG,IAAIV,GAAG,EAAE;MACrBO,IAAI,CAACI,YAAY,EAAE;IACvB;EAAC;IAAA;IAAA,OAGO,iBAAK;MACT,IAAI,CAACT,SAAS,CAAC;QACXU,OAAO,EAAE,KAAK;QACdC,MAAM,EAAE;OACX,CAAC;IACN;EAAC;IAAA;IAAA,OAEO,mBAAUC,CAAM;MACpB,IAAIP,IAAI,GAAG,IAAI;MAEfA,IAAI,CAACG,IAAI,CAACK,eAAe,CAAC,IAAIC,UAAU,CAACF,CAAC,CAACG,MAAM,CAACJ,MAAM,CAAC,CAAC;MAC1D,IAAIN,IAAI,CAACE,KAAK,GAAGF,IAAI,CAACH,SAAS,IAAIG,IAAI,CAACC,KAAK,CAACU,IAAI,EAAE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,IAAI,CAACJ,MAAM,EAAE;QACbI,IAAI,CAACgB,OAAO,GAAG,IAAIK,UAAU,EAAE;QAC/BrB,IAAI,CAACgB,OAAO,CAACM,MAAM,GAAGtB,IAAI,CAACmB,SAAS,CAACI,IAAI,CAACvB,IAAI,CAAC;QAC/CA,IAAI,CAACgB,OAAO,CAACQ,OAAO,GAAGxB,IAAI,CAACoB,KAAK,CAACG,IAAI,CAACvB,IAAI,CAAC;QAC5CA,IAAI,CAACgB,OAAO,CAACS,OAAO,GAAGzB,IAAI,CAACoB,KAAK,CAACG,IAAI,CAACvB,IAAI,CAAC;OAC/C,MAAM;QACHA,IAAI,CAACgB,OAAO,GAAG,IAAIU,cAAc,EAAE;;IAE3C;EAAC;EAAA;AAAA","names":["Md5","Md5FileHasher","_callback","_async","_partSize","_configureReader","blob","self","_blob","_part","_md5","_processPart","success","result","e","appendByteArray","Uint8Array","target","size","end","endbyte","current_part","slice","_reader","readAsArrayBuffer","setTimeout","_hashData","_fail","FileReader","onload","bind","onerror","onabort","FileReaderSync"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/ts-md5/src/md5_file_hasher.ts"],"sourcesContent":["import {Md5} from './md5';\n\ndeclare let FileReaderSync: any;\n\nexport interface HashingResponse {\n    success: boolean;\n    result?: string | Int32Array;\n}\n\n// Hashes any blob\nexport class Md5FileHasher {\n    private _reader: any;\n\n    private _md5!: Md5;\n    private _part!: number;\n    // private _length!: number;\n    private _blob: any;\n\n\n    constructor(\n        private _callback: (r: HashingResponse) => void,    // Callback to return the result\n        private _async: boolean = true,                     // Async version is not always available in a web worker\n        private _partSize: number = 1048576,                // 1mb\n    ) {\n        this._configureReader();\n    }\n\n    /**\n     * Hash a blob of data in the worker\n     * @param blob Data to hash\n     */\n    public hash(blob: any) {\n        const self = this;\n\n        self._blob = blob;\n        // self._length = Math.ceil(blob.size / self._partSize);\n        self._part = 0;\n        self._md5 = new Md5();\n        self._processPart();\n    }\n\n\n    private _fail() {\n        this._callback({\n            success: false,\n            result: 'data read failed'\n        });\n    }\n\n    private _hashData(e: any) {\n        let self = this;\n\n        self._md5.appendByteArray(new Uint8Array(e.target.result));\n        if (self._part * self._partSize >= self._blob.size) {\n            self._callback({\n                success: true,\n                result: self._md5.end()\n            });\n        } else {\n            self._processPart();\n        }\n    }\n\n    private _processPart() {\n        const self = this;\n        let endbyte = 0;\n        let current_part: any;\n\n        self._part += 1;\n\n        if (self._blob.size > self._partSize) {        // If blob bigger then part_size we will slice it up\n            endbyte = self._part * self._partSize;\n            if (endbyte > self._blob.size) {\n                endbyte = self._blob.size;\n            }\n            current_part = self._blob.slice((self._part - 1) * self._partSize, endbyte);\n        } else {\n            current_part = self._blob;\n        }\n\n        if (self._async) {\n            self._reader.readAsArrayBuffer(current_part);\n        } else {\n            setTimeout(() => {\n                try {\n                    self._hashData({\n                        target: {\n                            result: self._reader.readAsArrayBuffer(current_part)\n                        },\n                    });\n                } catch (e) {\n                    self._fail();\n                }\n            }, 0);\n        }\n    }\n\n    private _configureReader() {\n        const self = this;\n\n        if (self._async) {\n            self._reader = new FileReader();\n            self._reader.onload = self._hashData.bind(self);\n            self._reader.onerror = self._fail.bind(self);\n            self._reader.onabort = self._fail.bind(self);\n        } else {\n            self._reader = new FileReaderSync();\n        }\n    }\n}\n"]},"metadata":{},"sourceType":"module"}